package cn.iocoder.yudao.module.handguard.service.userbasetable11;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import java.util.*;
import cn.iocoder.yudao.module.handguard.controller.app.userbasetable11.vo.*;
import cn.iocoder.yudao.module.handguard.dal.dataobject.userbasetable11.UserBaseTable11DO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;

import cn.iocoder.yudao.module.handguard.convert.userbasetable11.UserBaseTable11Convert;
import cn.iocoder.yudao.module.handguard.dal.mysql.userbasetable11.UserBaseTable11Mapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.handguard.enums.ErrorCodeConstants.*;

/**
 * 税贷 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class UserBaseTable11ServiceImpl implements UserBaseTable11Service {

    @Resource
    private UserBaseTable11Mapper userBaseTable11Mapper;

    @Override
    public Long createUserBaseTable11(UserBaseTable11CreateReqVO createReqVO) {
        // 插入
        UserBaseTable11DO userBaseTable11 = UserBaseTable11Convert.INSTANCE.convert(createReqVO);
        userBaseTable11Mapper.insert(userBaseTable11);
        // 返回
        return userBaseTable11.getId();
    }

    @Override
    public void updateUserBaseTable11(UserBaseTable11UpdateReqVO updateReqVO) {
        // 校验存在
        validateUserBaseTable11Exists(updateReqVO.getId());
        // 更新
        UserBaseTable11DO updateObj = UserBaseTable11Convert.INSTANCE.convert(updateReqVO);
        userBaseTable11Mapper.updateById(updateObj);
    }

    @Override
    public void deleteUserBaseTable11(Long id) {
        // 校验存在
        validateUserBaseTable11Exists(id);
        // 删除
        userBaseTable11Mapper.deleteById(id);
    }

    private void validateUserBaseTable11Exists(Long id) {
        if (userBaseTable11Mapper.selectById(id) == null) {
            throw exception(USER_BASE_TABLE11_NOT_EXISTS);
        }
    }

    @Override
    public UserBaseTable11DO getUserBaseTable11(Long id) {
        LambdaQueryWrapper<UserBaseTable11DO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(UserBaseTable11DO::getApplicationId,id);
        return userBaseTable11Mapper.selectOne(queryWrapper);
    }

    @Override
    public List<UserBaseTable11DO> getUserBaseTable11List(Collection<Long> ids) {
        return userBaseTable11Mapper.selectBatchIds(ids);
    }

    @Override
    public PageResult<UserBaseTable11DO> getUserBaseTable11Page(UserBaseTable11PageReqVO pageReqVO) {
        return userBaseTable11Mapper.selectPage(pageReqVO);
    }

    @Override
    public List<UserBaseTable11DO> getUserBaseTable11List(UserBaseTable11ExportReqVO exportReqVO) {
        return userBaseTable11Mapper.selectList(exportReqVO);
    }

}
